package com.foreknow.elmboot.mapper;

import com.foreknow.elmboot.po.Cart;
import com.foreknow.elmboot.po.Orders;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface OrdersMapper {
    /**
     * 添加订单
     * @param order
     * @return
     */

    @Insert("insert into Orders(userId,businessId,orderDate,orderTotal,daId,orderState) values(#{userId},#{businessId},#{orderDate},#{orderTotal},#{daId},0)")
    @Options(useGeneratedKeys = true,keyProperty = "orderId")
    public int saveOrders(Orders order);

    /**
     * 根据orderId查询订单信息
     * @param orderId
     * @return
     */
    public Orders getOrdersById(Integer orderId);

    /**
     * 根据userId查询用户所有订单
     * @param userId
     * @return
     */
    public List<Orders> listOrderByUserId(String userId);

    /**
     * 根据orderId改变支付状态
     * @param orderId
     * @return
     */
    @Update("update orders set orderState=1 where orderId=#{orderId}")
    public int updateorderState(Integer orderId);
}
